package com.rjj.wlqq.wx.entity.template;

import com.rjj.wlqq.wx.tool.StrKit;

import java.util.HashMap;
import java.util.Map;

/**
 * @author r
 * @date 2020/12/26 22:26
 * <p>
 * 微信模版消息
 */
public class Template
{
    private String touser;

    private String template_id;

    private String url;

    private Map<String, Content> data = new HashMap<>();

    public static Template Builder()
    {
        return new Template();
    }

    public Template build()
    {
        if (StrKit.isBlank(this.touser))
        {
            throw new IllegalStateException("touser is null");
        } else if (StrKit.isBlank(this.template_id))
        {
            throw new IllegalStateException("template_id is null");
        } else if (StrKit.isBlank(this.url))
        {
            throw new IllegalStateException("url is null");
        } else if (!StrKit.notNull(this.data))
        {
            throw new IllegalStateException("data is null");
        } else
        {
            return new Template(this.touser, this.template_id, this.url, this.data);
        }
    }

    private Template()
    {
    }

    public Template(String touser, String template_id, String url, Map<String, Content> data)
    {
        this.touser = touser;
        this.template_id = template_id;
        this.url = url;
        this.data = data;
    }

    public String getTouser()
    {
        return this.touser;
    }

    public String getTemplate_id()
    {
        return this.template_id;
    }

    public String getUrl()
    {
        return this.url;
    }

    public Map<String, Content> getData()
    {
        return this.data;
    }

    public Template setTouser(String touser)
    {
        this.touser = touser;
        return this;
    }

    public Template setTemplate_id(String template_id)
    {
        this.template_id = template_id;
        return this;
    }

    public Template setUrl(String url)
    {
        this.url = url;
        return this;
    }

    public Template setData(String key, Content content)
    {
        this.data.put(key, content);
        return this;
    }

    public Template removeData(String key, Content content)
    {
        this.data.remove(key, content);
        return this;
    }

}


